require 'rubygems'
require 'ruby-growl'

module Jakl
  class GrowlHandler
    def initialize
      if `which growlnotify` =~ /^no .+ in/
        @strategy = :ruby
        @growl = Growl.new("localhost", "jakl", ["jakl_message"])
      else
        @strategy = :command
      end
    end
    
    def notify(group, name, message)
      case @strategy
        when :command
          img_path = File.join(File.dirname(__FILE__), '../../assets/jakl.png')
          `growlnotify -n jakl --image #{img_path} -m '#{message}' '#{name} (#{group})'`
        when :ruby
          @growl.notify("jakl_message", "#{name} (#{group})", message)
        else
          raise StandardError.new('Invalid strategy')
      end
    end
  end
end